package com.za.iyunbao.htmlspanner.demo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Spannable;
import android.widget.TextView;

import com.za.iyunbao.htmlspanner.HtmlSpanner;

import java.net.MalformedURLException;
import java.net.URL;

public class MainActivity extends AppCompatActivity {

    TextView textview;

    HtmlSpanner htmlSpanner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textview = (TextView) findViewById(R.id.textview);
        htmlSpanner = new HtmlSpanner();
        new Thread() {
            @Override
            public void run() {
                try {
                    final Spannable spannable = htmlSpanner.fromHtml(new URL("https://www.baidu.com/"));
                    if (spannable != null) {
                        textview.post(new Runnable() {
                            @Override
                            public void run() {
                                textview.setText(spannable);
                            }
                        });
                    }
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
            }
        }.start();

    }

}
